package com.controller;

import com.pojo.Goods;
import com.pojo.Member;
import com.pojo.Provider;
import com.pojo.User;
import com.service.SelectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("select")
public class SelectController {
    @Autowired
    private SelectService selectService;

    //加载了管理员管理用户模块的用户列表界面，并传入用户信息
    @RequestMapping("userTable")
    public ModelAndView getUser(){
        List<User> user = selectService.getUser();
        ModelAndView mv= new ModelAndView("table/usertable");
        mv.addObject("user",user);
        return mv;
    }

    /**
     * 用户点击查询用户按钮
     * 实现用户模糊查询
     * 1.加载用户查询界面
     * 2.实现查询功能
    **/
     @RequestMapping("selectUser")
    public ModelAndView selectUserLoad(String uservalue){
         List<User> users = selectService.selectUser(uservalue);
         ModelAndView mv= new ModelAndView("table/selectuser");
         if (users==null){
             User user = new User();
             user.setUserName(uservalue);
            users.set(0,user);
         }else {
             mv.addObject("uservalue",users);
         }
         return mv;
     }


    /**
     * 加载供应商列表界面，并查询所有供应商的所有信息
     * 1.加载供应商列表界面.并查询信息
     **/
    @RequestMapping("providerTable")
    public ModelAndView selectProviderLoad(){
        List<Provider> provider = selectService.getProvider();
        ModelAndView mv= new ModelAndView("table/providertable");
        mv.addObject("provider",provider);
        return mv;
    }
    /**
     * 用户点击查询供应商按钮
     * 实现供应商模糊查询
     * 1.加载供应商查询界面
     * 2.实现查询功能
     **/
    @RequestMapping("selectProvider")
    public ModelAndView selectProvider(String providervalue){
        List<Provider> providers = selectService.selectProvider(providervalue);
        ModelAndView mv = new ModelAndView("table/selectprovider");
        mv.addObject("provider",providers);
        return mv;
    }
    /**
     * 商品信息列表界面
     * 1.加载商品信息列表界面，并查询商品信息
     **/
    @RequestMapping("goodsTable")
    public ModelAndView goodsTable(){
        List<Goods> goods = selectService.getGoods();
        ModelAndView mv = new ModelAndView("table/goodstable");
        mv.addObject("goods",goods);
        return mv;
    }

    /**
     * 用户点击查询商品按钮
     * 实现商品模糊查询
     * 1.加载商品查询界面
     * 2.实现查询功能
     **/
    @RequestMapping("selectGoods")
    public ModelAndView selectGoods(String goodsvalue){
        ModelAndView mv = new ModelAndView("table/selectgoods");
        List<Goods> goods = selectService.selectGoods(goodsvalue);
        mv.addObject("goods",goods);
        return mv;
    }
    /**
     * 会员信息查询
     * 1.加载会员信息界面
     * 2.查询所有会员信息
     **/
    @RequestMapping("memberTable")
    public ModelAndView memberTable(){
        List<Member> member = selectService.getMember();
        ModelAndView mv = new ModelAndView("table/membertable");
        mv.addObject("member",member);
        return mv;
    }
    /**
     * 查找会员信息
     * 1.加载查询界面
     * 2.查询信息
     **/
    @RequestMapping("selectMember")
    public ModelAndView selectMember(String membervalue ){
        List<Member> members = selectService.selectMember(membervalue);
        ModelAndView mv= new ModelAndView("table/selectmember");
        mv.addObject("members",members);
        return mv;
    }
}
